package std.game.objects.views

import org.groovymud.object.MudObject
import org.groovymud.object.registry.InventoryHandler
import org.groovymud.shell.io.TerminalIO
import org.junit.Before
import org.junit.Test
import std.game.objects.alive.PlayerImpl
import std.game.objects.containers.RoomImpl
import utils.TerminalIOStub
import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.Matchers.*
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when
import org.groovymud.object.MudObjectWithNameAndDescription

class RoomViewTest {

    def room
    def helper
    RoomView underTest
    TerminalIO io
    InventoryHandler inventoryHandler

    def player

    @Test
    public void "room view shows correct body content without looker in content"() {
        final otherPerson = new PlayerImpl(name: "woo")
        when(inventoryHandler.getMudObjectsMap()).thenReturn(["someone": [player], "someoneelse": [otherPerson]])
        underTest.writeLookBody(player, room)
        assertThat(io.toString(), equalTo("f\n\t\t\tyou are somewherea\r\nYou see: Woo is here.\r\n"))
        assertThat(io.toString(), not(containsString("someone")))
    }

    @Test
    public void "room view shows correct body content with correct live content in footer"() {
        final otherPerson = new PlayerImpl(name: "woo")
        final thing = new org.groovymud.object.MudObjectWithNameAndDescription(name: "thing")

        when(inventoryHandler.getMudObjectsMap()).thenReturn([
                    "someone": [player],
                    "someoneelse": [otherPerson],
                    "thing": [thing]
        ])
        underTest.writeLookBody(player, room)
        assertThat(io.toString(), equalTo("f\n\t\t\tyou are somewherea\r\nYou see: A thing.\r\nWoo is here.\r\n"))
        assertThat(io.toString(), not(containsString("someoneelse")))
    }

    @Before
    public void setUp() {
        helper = new ContentsHelper()
        underTest = new RoomView(contentHelper: helper)
        io = new TerminalIOStub()
        inventoryHandler = mock(InventoryHandler)
        player = new PlayerImpl(name: "someone", description: "me", currentContainer: room, terminalOutput: io)
        room = new RoomImpl(name: "somewhere", description: "You are somewhere", inventoryHandler: inventoryHandler)
    }
}
